<template>
  <div class="tushu">
    <div v-html="long_img" class="longimg"></div>
    <div class="tushuList" v-loading="loading">
      <div class="classify">
        <!-- <div class="h_li flex">
          报考类型
          <li :class="choose_classify=='全部'?'classify_bg':''">全部</li>
          <li :class="choose_classify=='各省统考'?'classify_bg':''">各省统考</li>
          <li :class="choose_classify=='名校校考'?'classify_bg':''">名校校考</li>
        </div>-->
        <div class="h_li flex" style="margin-top:15px;">
          <p>报考专业</p>
          <li
            v-for="(list_f,list_index) in zhuanyef"
            :key="list_index"
            @click="listf(list_f.id)"
            :class="choose_id==list_f.id?'classify_bg':''"
          >{{list_f.name}}</li>
        </div>
      </div>
      <div class="class">
        <div class="class_one flex">
          <!-- <img src="../assets/tushu_book.png" alt /> -->
          艺考图书
        </div>
        <ul class="c_bottom">
          <li v-for="(list,index) in listarry" :key="index">
            <img :src="list.photo" alt @click="toDetail(list.id)" />
            <div
              class="hidden b_bottom_a"
              style="width:204px;margin-top:13px;margin-bottom:3px;"
              @click="toDetail(list.id)"
            >{{list.title}}</div>
            <div class="b_bottom_b flex" @click="toDetail(list.id)">
              <div>¥{{list.price}}元</div>
              <div>定价{{list.dingjia}}元</div>
            </div>
            <div
              class="c_bottom_d flex"
              style="margin-top:3px;margin-bottom:9px;"
              @click="toDetail(list.id)"
            >
              <!-- <el-rate
                v-model="list.star"
                disabled
                :colors="['#fc7023', '#fc7023', '#fc7023']"
                disabled-void-color="#999"
              ></el-rate> -->
              <div>{{list.buyNum}}人购买</div>
            </div>
            <div class="b_bottom_c flex" style="width:204px;" @click="addcar(list.id)">
              <!-- <img src="../assets/car_red.png" alt /> -->
              加入购物车
            </div>
          </li>


          <div class="page" v-if="total!=0">
            <div class="page_a" @click="handleCurrentChange(0)">首页</div>
            <el-pagination
              background
              @current-change="handleCurrentChange"
              :current-page.sync="currentPage"
              layout="prev, pager, next"
              :total="total"
              :page-size="9"
            ></el-pagination>
            <div class="page_a" @click="handleCurrentChange(1)">尾页</div>
          </div>
          <div v-else class="tip2">
            <img src="../assets/none.png" alt />
          </div>

        </ul>
        
      </div>
    </div>
  </div>
</template>

<script>
import {
  Professionallist,
  ykGoodslist,
  addcar,
  channelTime
} from "../api/index";
export default {
  props: {},
  data() {
    return {
      zhuanyef: [],
      xuankeA: {
        id: "",
        name: "全部"
      },
      choose_classify: "全部",
      choose_id: "",
      loading: true,
      currentPage: 1,
      total: 0, //列表总数
      pagenum: 1, //请求的页数
      pagesize: 9, //请求的数量
      listarry: [],
      long_img: ""
    };
  },
  computed: {},
  created() {},
  mounted() {
    let msg = {
      title: "艺考图书"
    };
    channelTime(this.qs(msg))
      .then(res => {
        // console.log(res)
        this.long_img = res.data.ykPc.content;
      })
      .catch(e => {});
    Professionallist()
      .then(res => {
        if (res.data.code == 0) {
          res.data.rows.unshift(this.xuankeA);
          this.zhuanyef = res.data.rows;
        }
      })
      .catch(e => {});
    this.post();
  },
  watch: {},
  methods: {
    post() {
      let msg = {
        type: "3",
        pId: this.choose_id,
        pageNum: this.pagenum,
        pageSize: this.pagesize
      };
      ykGoodslist(this.qs(msg))
        .then(res => {
          if (res.data.code == 0) {
            for (let i = 0; i < res.data.rows.length; i++) {
              res.data.rows[i].star = res.data.rows[i].star - 0;
            }
            this.listarry = res.data.rows;
            this.total = res.data.total;
            // console.log(this.listarry);
          }
          this.loading = false;
        })
        .catch(e => {});
    },
    //切换选项
    listf(id) {
      this.choose_id = id;
      this.pagenum = 1;
      this.currentPage = 1;
      this.post();
    },
    handleCurrentChange(val) {
      if (val == "w") {
        this.pagenum = Math.ceil(this.total / this.pagesize);
      } else {
        this.pagenum = val;
      }
      this.currentPage = this.pagenum;
      this.loading = true;
      this.post();
      document.body.scrollTop = 200;
      document.documentElement.scrollTop = 200;
    },
    //详情
    toDetail(id) {
      this.$router.push({
        name: "tushuDetail",
        params: {
          id: id
        }
      });
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    },
    addcar(id) {
      if (localStorage.getItem("YKuserid")) {
        let msg = {
          userId: localStorage.getItem("YKuserid"),
          goodsId: id,
          booknum: 1
        };
        addcar(this.qs(msg))
          .then(res => {
            this.$message({
              type: "info",
              message: res.data.msg
            });
            if (res.data.code == 0) {
              this.info = res.data.ykGoods;
              this.$parent.touserDetail();
            }
          })
          .catch(e => {});
      } else {
        this.$parent.tologin();
        // this.$message({
        //   type: "error",
        //   message: "请登录"
        // });
        return;
      }
    }
  },
  components: {}
};
</script>

<style scoped>
.tushu {
  /* background: #f5f8f7; */
}
.tushuList {
  width: 1200px;
  margin: 0 auto;
}
.longimg {
  width: 100%;
  height: 350px;
}
/* 分类 */
.classify {
  width: 100%;
  padding: 20px 0px;
  /* background: #fff; */
}

.h_li p{
  line-height: 60px;
  padding-bottom: 20px;
  font-size: 16px;
  color: #fff;
  margin-right: 20px;
}
.h_li li {
  font-size: 16px;
  font-weight: normal !important;
  color: #fff;
  cursor: pointer;
  padding:0 10px;
  line-height: 60px;
  padding-bottom: 20px;
}
.h_li li:hover {
  color: #c8a94f;
}
.h_li li.classify_bg {
  color: #c8a94f;
  background: url(../assets/nav_active_bg.png) no-repeat;
  background-position: center center;
}
/* ul */
.class {
  width: 100%;
  background: #363640;
  padding-top: 30px;
  padding-bottom: 50px;
  margin-bottom: 50px;
}
.class_one {
  font-size: 24px;
  font-weight: bold;
  color: #fff;
  margin-bottom: 30px;
  padding:0 33px;
}
.class_one > img {
  width: 25px;
  height: 24px;
  margin-left: 14px;
  margin-right: 9px;
}
.c_bottom {
  display: flex;
  flex-wrap: wrap;
  margin-left: 51px;
  margin-right: 51px;
  background: url('../assets/booklist_bg.png') no-repeat;
  background-size: 100% auto;
  padding-bottom: 530px;
}
.c_bottom li {
  width: 344px;
  padding-bottom: 20px;
  padding-top: 12px;
  margin-bottom: 28px;
  box-sizing: border-box;
  margin-right: 33px;
  cursor: pointer;
}
.c_bottom li:nth-child(3n) {
  margin-right: 0px !important;
}
.c_bottom li > img {
  width: 236px;
  height: auto;
  margin: 0 auto;
  border-radius: 20px;
}
.c_bottom li:hover {
  /* border: 1px solid #c8a94f; */
}
.c_bottom_d {
  justify-content: center;
  align-content: center;
}
.c_bottom_d >>> .el-rate__icon {
  margin-right: 0;
  font-size: 14px;
}
.c_bottom_d >>> .el-rate {
  height: 14px;
  line-height: 0px;
}
.c_bottom_d > div {
  color: #7c7e8d;
  font-size: 12px;
  margin-left: 4px;
}
.b_bottom_a {
  width: 268px;
  margin: 0 auto;
  font-size: 16px;
  color: #c3c4c9;
  margin-top: 15px;
  margin-bottom: 15px;
  text-align: center;
}
.b_bottom_b {
  justify-content: center;
}
.b_bottom_b > div {
  font-size: 14px;
}
.b_bottom_b > div:first-child {
  color: #c8a94f;
  margin-right: 5px;
}
.b_bottom_b > div:last-child {
  color: #999;
  text-decoration: line-through;
}
.b_bottom_c {
  width: 268px;
  height: 36px;
  border: 1px solid #c8a94f;
  margin: 0 auto;
  justify-content: center;
  margin-top: 7px;
  color: #c8a94f;
  font-size: 14px;
  border-radius: 36px;
}
.b_bottom_c > img {
  width: 14px;
  height: 12px;
  margin-right: 4px;
}
/* page */
.page {
  display: flex;
  justify-content: center;
  margin:0 auto;
  margin-top: 30px;
  margin-bottom: 49px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.page >>> .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #c8a94f !important;
}
.page >>> .el-pager li,
.page >>> .btn-next,
.page >>> .btn-prev {
  width: 34px;
  height: 34px;
  padding: 0;
  line-height: 34px;
  text-align: center;
  border-radius: 5px;
}
.page_a {
  width: 34px;
  height: 34px;
  background: #7a7d90;
  border-radius: 5px;
  font-size: 12px;
  color: #fff;
  line-height: 34px;
  text-align: center;
}
.page_a:hover {
  background: #c8a94f;
  color: #fff;
}
</style>
